﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;

public partial class Admin_AddMovie : System.Web.UI.Page
{
    Product pd = new Product();
    public static string name;
    protected void Page_Load(object sender, EventArgs e)
    {
        txtMovieID.Text = pd.getID();
    }
    protected void btnSummit_Click(object sender, EventArgs e)
    {
        DataClassesDataContext dtc = new DataClassesDataContext();      
        try
        {
            if( pd.AddMovie(pd.getID(), txtMovieName.Text, txtFilmDirector.Text, txtActors.Text, txtCa.Text, txtCountry.Text, upload(), txtAboutMovie.Text, DateTime.Parse(txtReleasedDate.Text.Trim()), DateTime.Parse(txtCloseDay.Text.Trim()), int.Parse(ddlStatus.SelectedValue), txtNotes.Text))
            {
                Response.Redirect("AddMovie.aspx");
            }
            
        }
        catch(Exception ex)
        {
            lblError.Visible = true;
            lblError.Text ="No"+ ex.ToString();
        }


    }
    string upload()
    {

        if (UploadImage.HasFile)
        {
            Random rb = new Random();
            int rand = rb.Next(1000);
            string name = rand.ToString() + "_" + UploadImage.PostedFile.FileName;
            try
            {
                UploadImage.SaveAs(Server.MapPath("~/images/Movie/" + name));
                return name;
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
        else
        {
            return "no-picture.jpg";
        }
        
    }
}